<template>
	<view>
		<view v-if="total>0">
			<view class="order_list">
				<view class="order" v-for="(item,index) in list" :v-key="index">
						<!--列表商品图片-->
						<view class="order_text">
							<!--列表标题-->
							<view class="title">
								<text v-if="item.ptype==0"
									style="font-size:1.5rem;font-weight:both;color:#000000">金额满减</text>
								<text v-if="item.ptype==1"
									style="font-size:1.5rem;font-weight:both;color:#000000">积分满减</text>
								<text v-if="item.ptype==2"
									style="font-size:1.5rem;font-weight:both;color:#000000">订单数满减</text>
								<!-- <text style="color:#666;margin-left:20rpx;font-size:1rem">{{item.usetype}}</text> -->
								<u-tag v-if="item.isflag==1" type="success" circle text="开启" size="small"></u-tag>
								<u-tag v-else type="error" circle text="关闭" size="small"></u-tag>
							</view>
							<view style="color:#666;margin:20rpx 0rpx">
								<!-- <image src="/images/serch/detel.png" /> -->
								<text decode>活动时间{{item.starttime}}&nbsp;至&nbsp;{{item.endtime}}</text>
							</view>
							<u-row gutter="10">
								<u-col span="6">
									<view style="font-size:1rem">
										满<text style="color:#F66B71;font-size:1.3rem"
											decode>{{item.pcondition}}&nbsp;&nbsp;&nbsp;&nbsp;</text>
										减<text style="color:#F66B71;font-size:1.3rem">{{item.remoney}}</text>
									</view>
								</u-col>
								<u-col span="6">
									<view style="display:flex;text-align:right;align-items: center;">
										<u-button color="#F66B71" size="mini" style="width:60rpx;"
											@click="onEdit(item)">修改</u-button>
										<view>
											<u-button v-if="item.isflag=='1'" size="mini" color="#000000"
												style="width:60rpx;margin-left:40rpx;" @click="setActive(0,item.pcode)">关闭</u-button>
											<u-button v-else color="#228B22" size="mini" style="width:60rpx;margin-left:20rpx;"
												@click="setActive(1,item.pcode)">开启</u-button>
										</view>
									</view>
								</u-col>
							</u-row>
					</view>
				</view>
			</view>

			<!--固定底部-->
			<view class="buy">
				<u-button type="error" size="large" @click="onEdit">添加活动</u-button>
				<!-- <u-button color="#000000">删除</u-button> -->
			</view>
		</view>
		<!--购物车没订单-->
		<view v-else>
			<view class="list_none">暂无活动~</view>
			<u-button style="width:200rpx;margin: auto;" size="mini" @click="onEdit">添加活动</u-button>
		</view>
	</view>
</template>

<script>
	import Config from '@/util/index.js'
	export default {
		data() {
			return {
				hasList: true, //默认展示列表数据
				radio: '1',
				activeinfo: [],
				isflag: '0', //关闭
				total: 0,
				nodata: false,
				//商品列表数据
				list: [],
				//金额
				totalPrice: 0, //总价，初始为0
				//全选状态
				selectAllStatus: true, // 全选状态，默认全选
				pagenum: -1,
				pagesize: 5,
				rcode: '',
				moreData: false
			}
		},
		onLoad(options) {
			if (this.rcode == "") {
				this.rcode = options.rcode
			}
			console.log("this.rcode", this.rcode)
			this.getActive()
		},
		methods: {
			getActive() {
				if (this.moreData) {
					return false
				} else {
					this.pagenum++
				}
				uni.showLoading({
					title: '加载中...',
				})
				let params = {
					mid: uni.getStorageSync('loginInfo').mid,
					rcode: this.rcode,
					pagenum: this.pagenum,
					pagesize: this.pagesize
				}
				let _this = this
				Api.searchActive(params).then(res => {
					if (res.pagetotal > 0) {
						const newList = res.promotions
						uni.hideLoading()
						const total = res.pagetotal
						if (_this.list.length < total) {
							_this.list = [..._this.list, ...newList]
							_this.total = total
						} else {
							_this.moreData = true
						}
					} else {
						uni.hideLoading()
						if (_this.pagenum == 0) {
							_this.nodata = true
						}
						_this.moreData = true
					}
				})
			},
			setActive(state, act_id) {
				let params = {
					pcode: act_id,
					isflag: state
				}
				let _this = this
				Api.activeState(params).then(res => {
					if (res.retCode == 0) {
						if (state == 0) {
							uni.showToast({
								title: "关闭成功",
								icon: 'none',
								duration: 2000
							});
						} else {
							uni.showToast({
								title: "启用成功",
								icon: 'none',
								duration: 2000
							});
						}
						_this.pagenum = -1
						_this.list = []
						_this.moreData = false
						_this.getActive()
					} else {
						console.log(res.info)
					}
				})
			},

			onEdit(activeInfo) {
				if (activeInfo) {
					uni.navigateTo({
						url: 'active-edit?rcode=' + this.rcode + '&actifo=' + JSON.stringify(activeInfo),
					})
				} else {
					uni.navigateTo({
						url: 'active-edit?rcode=' + this.rcode + '&actifo=' + activeInfo,
					})
				}
			},
		},
		onReachBottom: function() {
			this.getActive()
		},
	}
</script>

<style scoped>
	/* pages/manage/storeinfo/home.wxss */
	page {
		background-color: rgba(238, 238, 238, 0.5);
	}

	.order {
		background-color: #fefeff;
		margin: 27rpx 0rpx;
		border-radius: 4rpx;
	}

	.xuanze {
		width: 40rpx;
		height: 40rpx;
		/* background-color: darkgoldenrod; */
		border-radius: 50%;
		margin: 0 11rpx;
	}

	.xuanze image {
		width: 100%;
		height: 100%;
		display: block;
		border-radius: 50%;
	}

	.order_img {
		width: 180rpx;
		height: 180rpx;
	}

	.order_img image {
		width: 100%;
		height: 100%;
		display: block;
	}

	.order_text {
		padding:20rpx;
		width: 90%;
		height: auto;
	}

	.text_top {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.title {
		width: 70%;
		font-size: 28rpx;
		color: #4b5248;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		overflow: hidden;
	}

	.detel {
		width: 30rpx;
		height: 30rpx;
	}

	.detel image {
		width: 100%;
		height: 100%;
		display: block;
	}

	.size {
		font-size: 24rpx;
		color: #a8ada6;
	}

	.text_bottom {
		display: flex;
		margin-top: 50rpx;
		align-items: center;
		justify-content: space-between;
	}

	.money {
		font-size: 30rpx;
		color: #a5937f;
	}

	.number {
		display: flex;
		justify-content: space-around;
		align-items: center;
		width: 170rpx;
	}

	.reduce {
		width: 46rpx;
		height: 46rpx;
	}

	.reduce image {
		width: 100%;
		height: 100%;
		display: block;
	}

	.numb {
		font-size: 30rpx;
		color: #a5937f;
	}

	.add {
		width: 46rpx;
		height: 46rpx;
	}

	.add image {
		width: 100%;
		height: 100%;
		display: block;
	}

	/*购买按钮*/

	.buy {
		width: 100%;
		position: fixed;
		bottom: 0rpx;
		background-color: #ffffff;
		z-index: 999;
	}

	.buy_top {
		border-bottom: 1px solid rgb(98, 98, 99);
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.top_left {
		display: flex;
		align-items: center;
	}

	.left_img {
		width: 37rpx;
		height: 37rpx;
		margin: 11rpx;
	}

	.left_img image {
		width: 100%;
		height: 100%;
		display: block;
	}

	.left_name {
		font-size: 24rpx;
		color: #000000;
		margin-right: 29rpx;
	}

	.buy_bottom {
		display: flex;
		height: 104rpx;
		justify-content: space-between;
		align-items: center;
		padding: 0rpx 30rpx 0rpx 12rpx;
	}

	.buy_left {
		font-size: 26rpx;
		color: #fff;
	}

	.buy_right {
		display: flex;
		align-items: center;
	}

	.liji {
		width: 180rpx;
		height: 70rpx;
		border: 2rpx solid rgba(248, 248, 248, 1);
		box-sizing: border-box;
		border-radius: 4rpx;
		line-height: 70rpx;
		text-align: center;
		font-size: 26rpx;
		color: #FEFEFF;
	}

	.two {
		margin-left: 12rpx;
	}

	.active {
		background-color: #A5937F;
		border: none;
	}

	.list_none {
		padding: 20rpx;
		color: #ff0000;
		text-align: center;
	}

	.order_list {
		margin-bottom: 100rpx
	}
</style>
